package com.zzy.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.zzy.model.AjaxMsg;
import com.zzy.model.UserModel;
import com.zzy.service.ActiveMQService;
import com.zzy.service.RedisService;
import com.zzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;

import java.util.*;

@Controller
@RequestMapping("/mq")
public class ActiveMQController {

    @Autowired
    private ActiveMQService activeMQService;
    private String prefix = "mq/";

    @Autowired
    public ActiveMQController(ActiveMQService activeMQService) {
        this.activeMQService = activeMQService;
    }


    @RequestMapping(value = "/send/queue")
    @ResponseBody
    public AjaxMsg send(@RequestParam(value = "msg") String msg) {
        Map map = new HashMap();
        map.put("msg",msg);
        map.put("other","你是大沙雕queue。");
        activeMQService.sendQueueMsg(map);
        return AjaxMsg.returnAjaxMsg(map);
    }

    @RequestMapping(value = "/send/topic")
    @ResponseBody
    public AjaxMsg topic(@RequestParam(value = "msg") String msg) {
        Map map = new HashMap();
        map.put("msg",msg);
        map.put("other","你是大沙雕topic。");
        activeMQService.sendTopicMsg(map);
        return AjaxMsg.returnAjaxMsg(map);
    }

    @RequestMapping(value = "/receive")
    @ResponseBody
    public AjaxMsg receive(@RequestParam(value = "name") String name) {
        System.out.println(name);
        String ss = activeMQService.getQueueMsg("spring-queue");
        return AjaxMsg.returnAjaxMsg(ss);
    }




    @RequestMapping(value = "/test")
    @ResponseBody
    public AjaxMsg test() {

        return AjaxMsg.returnAjaxMsg();
    }

}